import dynamic from 'dva/dynamic';
import app from '../app';

const commonArr = [import('../models/base')];

const createComponent = (component: any, arr: any[] = []) => {
  const obj: any = {
    app,
    models: () => [...commonArr, ...arr],
    component,
  };
  return dynamic(obj);
};

const Login = createComponent(() => import('@/pages/login'));
const Home = createComponent(() => import('@/pages/layout'));
const Index = createComponent(() => import('@/pages/home'));
const User = createComponent(() => import('@/pages/user'));
const DataCenter = createComponent(() => import('@/pages/data'));
const NoPage = createComponent(() => import('@/pages/404'));

const routes: any[] = [
  {
    path: '/',
    component: Home,
    routes: [
      {
        path: '/',
        exact: true,
        component: Index,
        name: '今日直播榜',
        header: true,
      },
      {
        path: '/user/:id',
        component: User,
        name: '中心',
        header: false,
      },
      {
        path: '/data/:id',
        component: DataCenter,
        name: '数据中心',
        header: false,
      },
      {
        path: '/404',
        component: NoPage,
        name: '空页面',
        header: false,
      },
      {
        path: '/login',
        component: Login,
        name: '登录',
        header: false,
      },
    ],
  },
];

export default routes;
